package com.example.easycharge.config;

import io.swagger.v3.oas.models.Components;
import io.swagger.v3.oas.models.ExternalDocumentation;
import io.swagger.v3.oas.models.OpenAPI;
import io.swagger.v3.oas.models.info.Info;
import io.swagger.v3.oas.models.info.License;
import io.swagger.v3.oas.models.security.SecurityRequirement;
import io.swagger.v3.oas.models.security.SecurityScheme;
import org.springdoc.core.GroupedOpenApi;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class SpringDocConfig {
    private static final String SECURITY_SCHEME_NAME = "BearerAuth";

    @Bean
    public OpenAPI mallTinyOpenAPI() {
        return new OpenAPI()
                .info(new Info().title("Mall-Tiny API")
                        .description("SpringDoc API 演示")
                        .version("v1.0.0")
                        .license(new License().name("Apache 2.0").url("https://github.com/macrozheng/mall-learning")))
                .externalDocs(new ExternalDocumentation()
                        .description("波普特大学充电桩管理项目"))
                .addSecurityItem(new SecurityRequirement().addList(SECURITY_SCHEME_NAME))
                .components(new Components()
                        .addSecuritySchemes(SECURITY_SCHEME_NAME,
                                new SecurityScheme()
                                        .name(SECURITY_SCHEME_NAME)
                                        .type(SecurityScheme.Type.HTTP)
                                        .scheme("bearer")
                                        .bearerFormat("JWT")));
//                        .url("http://www.macrozheng.com"));
    }

    @Bean
    public GroupedOpenApi alertApi() {
        return GroupedOpenApi.builder()
                .group("alert")
                .pathsToMatch("/alert/**")
                .build();
    }

    @Bean
    public GroupedOpenApi apiApi() {
        return GroupedOpenApi.builder()
                .group("api")
                .pathsToMatch("/api/**")
                .build();
    }

    @Bean
    public GroupedOpenApi billApi() {
        return GroupedOpenApi.builder()
                .group("bill")
                .pathsToMatch("/bill/**")
                .build();
    }

    @Bean
    public GroupedOpenApi chargeApi() {
        return GroupedOpenApi.builder()
                .group("charge")
                .pathsToMatch("/charge/**")
                .build();
    }

    @Bean
    public GroupedOpenApi userApi() {
        return GroupedOpenApi.builder()
                .group("user")
                .pathsToMatch("/user/**")
                .build();
    }

    @Bean
    public GroupedOpenApi messageItemApi() {
        return GroupedOpenApi.builder()
                .group("messageItem")
                .pathsToMatch("/messageItem/**")
                .build();
    }

    @Bean
    public GroupedOpenApi pileApi() {
        return GroupedOpenApi.builder()
                .group("pile")
                .pathsToMatch("/pile/**")
                .build();
    }

    @Bean
    public GroupedOpenApi queueApi() {
        return GroupedOpenApi.builder()
                .group("queue")
                .pathsToMatch("/queue/**")
                .build();
    }

    @Bean
    public GroupedOpenApi recordApi() {
        return GroupedOpenApi.builder()
                .group("record")
                .pathsToMatch("/record/**")
                .build();
    }

    @Bean
    public GroupedOpenApi vehicleApi() {
        return GroupedOpenApi.builder()
                .group("vehicle")
                .pathsToMatch("/vehicle/**")
                .build();
    }
}
